package com.hongminzheng.openapi.bean;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author hmz
 * @version 1.0
 * @date 2020-09-28
 **/
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public ModelAndView selectException(Exception e){
        ModelAndView modelAndView = new ModelAndView();
        if(e instanceof RuntimeException) {
            modelAndView.setViewName("error");
            modelAndView.addObject("errorMsg", "服务器正忙，请稍后再试");
        }
        return modelAndView;
    }


    @ExceptionHandler(UpdateException.class)
    @ResponseBody
    public Result layuiUpdateException(Exception e){
        return new Result(false, e.getMessage());
    }

}
